﻿#ifndef DESKTOPWEATHER_H
#define DESKTOPWEATHER_H

#include <QMainWindow>
#include <QSystemTrayIcon>
#include <QDateTime>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonParseError>
#include <QTimer>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QSettings>
#include <QFile>
#include <QInputDialog>
#include <QDir>
#include <QIcon>
#include <QPixmap>
#include <QImage>

QT_BEGIN_NAMESPACE
namespace Ui { class DesktopWeather; }
QT_END_NAMESPACE

class DesktopWeather : public QMainWindow
{
    Q_OBJECT

public:
    DesktopWeather(QWidget *parent = nullptr);
    ~DesktopWeather();
    void keyPressEvent(QKeyEvent* e);
    void mousePressEvent(QMouseEvent *mousePress);
    void mouseMoveEvent(QMouseEvent *mouseMove);
    void mouseReleaseEvent(QMouseEvent *mouseRelease);

    void programInit();

    void getNowWeather();
    void setNowWeather(const QString& path, const QString& text, int code, const QString& temperature);

    void getLivingIndex();
    void setLivingIndex(const QString& uv,
                        const QString& dressing,
                        const QString& flu,
                        const QString& car_washing,
                        const QString& travel,
                        const QString& sport);
    void getThreeDays();
    void setThreeDays(const QString& date,
                      int code_day,
                      const QString& temp,
                      const QString& weather,
                      int index);
protected slots:
    //天气实况
    void NowWeatherReply(QNetworkReply *Reply);
    //生活指数
    void LivingIndexReply(QNetworkReply *Reply);
    //未来三天天气
    void ThreeDaysReply(QNetworkReply *Reply);
private:
    Ui::DesktopWeather *ui;
    QSystemTrayIcon *trayicon;
    QPoint pressPoint;  //鼠标右键按下坐标
    int pressMouseButton;   //鼠标按键

    QSettings* UserParameter;

    QString user_location = "";
    QString user_apikey = "";

    const QString NowWeatherBaseUrl = "https://api.seniverse.com/v3/weather/now.json?language=zh-Hans&unit=c&";
    QString NowWeatherUrl = "";
    int code = 0;

    const QString LivingIndexBaseUrl = "https://api.seniverse.com/v3/life/suggestion.json?language=zh-Hans&";
    QString LivingIndexUrl = "";

    const QString ThreeDaysBaseUrl = "https://api.seniverse.com/v3/weather/daily.json?language=zh-Hans&unit=c&start=0&days=3&";
    QString ThreeDaysUrl = "";

    QNetworkAccessManager* NetworkAccessManager;
    QNetworkRequest NetworkRequest;

    QTimer* Timer;
    QTimer* NowWeatherTimer;
};
#endif // DESKTOPWEATHER_H
